Supported with v3.0.0+

The Dice Roller Widget is a widget you can add to your game to easily add dice rolling support, from the middle of the screen or from the user's drawer position.

This widget assumes the project has the standard gravity set within your project.

For any user support, the widget assumes the camera is set in a way where the edges of the dice roller match up with the edges of the screen to allow the dice rolls to come from the user's drawer location.

Step-by-Step

You can add the Dice Roller Widget through the Gameboard menu options at Gameboard > Tool > Add Dice Roller Widget

*WARNING* This will modify your camera settings to line up with the widget. If you don't want this to happen, the prefab can be found in Package > Gameboard Unity Plugin > Runtime > Tools > Prefabs > DiceRoller.prefab

Step-by-Step

This will add the gameboard SDK (if it doesn't already exist) and align the camera to support the user dice rolling, so the dice would roll from the user's drawer location.

Step-by-Step

Now that you have the prefab pulled into your project, you're presented with a few options to customize the dice widget.

Step-by-Step

Now that you have your dice roller configured, you will want to start rolling dice. For all of the methods the allowing rolling and modifying the dice, there are two events that will be important to listen to:

void Start()
{
    roller.DiceRollCompleted += RollComplete;
    roller.DiceRollTotalChanged += RollValueChanged;
}

void RollComplete(int result)
{
    // result after roll
}

void RollValueChanged(int result)
{
    // result after any change (roll, clear dice, etc)
}

There are a few methods available that you can use to roll dice depending on how you have configured your dice roller.

RollDice(int[] diceSizes)

RollDiceForUser(int[] diceSizes, string userId)

ReRollCurrentDice()

  roller.ReRollCurrentDice();

ClearDice()

  roller.ClearDice();

ClearDiceForUser(string userId)

  roller.ClearDiceForUser(userPresence.userId);

The Dice Roller will roll GameboardDice. You can create your own dice if they inherit from the GameboardDice object. GameboardDice will have the following usefil properties:

There are also some useful methods that can be used on the GameboardDice object:

Each GameboardDice also has it's own event called RollCompleted that you can listen to if you want to perform actions based on specific die rolls. That event returns the GameboardDice object that was rolled, and the int result of that roll.

This section include the entire code in one single, easy to copy section.

public GameboardDiceRoller roller;
private UserPresenceController userPresenceController;

void Start()
{
    GameObject gameboardObject = GameObject.FindWithTag("Gameboard");

    roller.DiceRollCompleted += RollComplete;
    roller.DiceRollTotalChanged += RollValueChanged;

    userPresenceController = gameboardObject.GetComponent<UserPresenceController>();
    userPresenceController.OnUserPresence += OnUserPresence;
}

void RollComplete(int result)
{
    // result after roll
}

void RollValueChanged(int result)
{
    // result after any change (roll, clear dice, etc)
}

public void RollDice()
{
    roller.RollDice(new int[7] { 4, 6, 6, 8, 10, 12, 20 });
}

public void ReRollCurrentDice()
{
    roller.ReRollCurrentDice();
}

public void ClearDice()
{
    roller.ClearDice();
}

private void OnUserPresence(GameboardUserPresenceEventArgs userPresence)
{
    switch (userPresence.changeValue)
    {
        case DataTypes.UserPresenceChangeTypes.REMOVE:
            roller.ClearDiceForUser(userPresence.userId);
            break;
        case DataTypes.UserPresenceChangeTypes.CHANGE_POSITION:
        case DataTypes.UserPresenceChangeTypes.CHANGE:
            roller.RollDiceForUser(new int[2] { 6, 6 }, userPresence.userId);
            break;
    }
}